import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import getPageTitle from '@/utils/pageTitle'
const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    component: () => import('components/Layout/index.vue'),
    redirect: '/index',
    children: [
      {
        path: '/index',
        name: 'Home',
        component: () => import('../views/Home/index.vue'),
        meta: {
          title: '课程列表',
          keepAlive: true,
        },
      },
      {
        path: '/detail/:id',
        name: 'Detail',
        meta: {
          title: '课程详情',
          keepAlive: true,
        },
        component: () => import('../views/Detail/index.vue'),
      },
    ],
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
})

router.beforeEach((to: any, from, next) => {
  // if (isLogin) {
  //   next()
  // } else {
  //   console.log('测试')
  //   next('login')
  // }
  next()
  document.title = getPageTitle(to?.meta?.title)
})

export default router
